package com.scs.application.modules.dept.controller;

import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.dept.dto.DeptReturnDTO;
import com.scs.application.modules.dept.entity.DeptReturnItem;
import com.scs.application.modules.dept.service.DeptReturnItemService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 */
@RestController
@RequestMapping("/dept/return_item")
public class DeptReturnItemController extends CrudController<DeptReturnItemService, DeptReturnItem> {

    @PostMapping("/scan")
    @Transactional(rollbackFor = Exception.class)
    public RestResult addByScan(@RequestBody @Valid DeptReturnDTO deptReturnDTO) {
        service.addByScan(deptReturnDTO.getDeptReturnId(), deptReturnDTO.getUniqueCode(), deptReturnDTO.getDeptId());
        return RestResult.ok();
    }

    @PostMapping("/addBySelect")
    synchronized public RestResult addBySelect(@RequestBody Map<String, Object> map) {
        service.addBySelect(map);
        return RestResult.ok();
    }
}
